using System;
using System.IO;
using System.Data;
using System.Windows.Forms;
using Scenario.WorkflowEngine.DataModel.WorkflowProcesses;
using Scenario.WorkflowEngine.DataModel.WorkflowParticipantsData;
using Scenario.WorkflowEngine.DataModel;
using Scenario.WorkflowEngine.DataModel.Common;

using WorkflowRelevantData = Scenario.WorkflowEngine.DataModel.WorkflowRelevantData;
using WorkflowApplicationsData = Scenario.WorkflowEngine.DataModel.WorkflowApplicationsData;
using WorkflowDataTypes = Scenario.WorkflowEngine.DataModel.WorkflowDataTypes;
using WorkflowProcesses = Scenario.WorkflowEngine.DataModel.WorkflowProcesses;
using Specialized = System.Collections.Specialized;
using Scenario.WorkflowEngine;

namespace Scenario.Modeler
{
	/// <summary>
	/// Descrizione di riepilogo per frmActivity.
	/// </summary>
	public class FormActivity : System.Windows.Forms.Form
	{
		private XMLRoles xmlRoles;

		private WorkflowDataTypes.XMLDataTypes m_DataTypes;
		private XMLActivity xmlActivity;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.TabControl tabBehaviour;
		private System.Windows.Forms.TabPage tabStart;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtReportStart;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.RadioButton rdAutomaticStart;
		private System.Windows.Forms.RadioButton rdManualStart;
		private System.Windows.Forms.TabPage tabExecution;
		private System.Windows.Forms.GroupBox groupBox4;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.ComboBox cmbScriptType;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TabPage tabFinish;
		private System.Windows.Forms.ComboBox cmbExecutionType;
		private System.Windows.Forms.ComboBox cmbDataTypes;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.GroupBox groupBox5;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.CheckBox chkOnlyOne;
		private System.Windows.Forms.Button btnAction;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.RadioButton rdAutomaticExecution;
		private System.Windows.Forms.RadioButton rdManualExecution;
		private System.Windows.Forms.RadioButton rdAutomaticFinish;
		private System.Windows.Forms.RadioButton rdManualFinish;
		private System.Windows.Forms.TextBox txtReportFinish;
		private System.Windows.Forms.TextBox txtReportExecution;
		/// <summary>
		/// Variabile di progettazione necessaria.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private const string Attribute_MASTER = "Data Object";
		private const string Gateway_MASTER = "Gateway";
		private const string COLLAPSED_SUBPROCESS_MASTER = "Collapsed Sub-Process";

		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.ComboBox cmbCatchType;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cmbType;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtDescription;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.Button btnAttributes;
		private System.Windows.Forms.Button btnGrants;
		private System.Windows.Forms.Button btnName;
		private System.Windows.Forms.CheckBox chkViewName;

		WorkflowRelevantData.XMLAttributes vAttributes = null;

		public FormActivity()
		{
			//
			// Necessario per il supporto di Progettazione Windows Form
			//
			InitializeComponent();

			//
			// TODO: aggiungere il codice del costruttore dopo la chiamata a InitializeComponent
			//
			xmlActivity=new XMLActivity();

		}

		/*
        public FormActivity(ref XMLRoles vRoles) :this()
		{
			xmlRoles  = vRoles;

			this.LoadControl(string.Empty);
		}
        */

		public FormActivity(ref XMLRoles _xmlRoles): this()
		{
            /*
			xmlRoles  = _xmlRoles;
            String sShapeId = "";// Utility.GetMasterNameU(oSelectedShape);
			this.LoadControl(sShapeId);

			try
			{
				this.Text="Activity:" + oSelectedShape.Text;

				this.BindObject(oSelectedShape);

				if ( ( oSelectedShape.Text == null) || ( oSelectedShape.Text == string.Empty ) )
				{
					this.chkViewName.Checked = false;
				}

			}
			catch(Exception err)
			{
				System.Console.WriteLine(err.Message);
				throw(err);
			}
            */
		}

		public WorkflowRelevantData.XMLAttributes XMLAttributes 
		{
			set { vAttributes = value; }
		}


		/// <summary>
		/// Pulire le risorse in uso.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		
		#region Codice generato da Progettazione Windows Form
		/// <summary>
		/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
		/// il contenuto del metodo con l'editor di codice.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormActivity));
            this.panel2 = new System.Windows.Forms.Panel();
            this.btnName = new System.Windows.Forms.Button();
            this.btnCancel = new System.Windows.Forms.Button();
            this.btnSave = new System.Windows.Forms.Button();
            this.tabBehaviour = new System.Windows.Forms.TabControl();
            this.tabStart = new System.Windows.Forms.TabPage();
            this.chkOnlyOne = new System.Windows.Forms.CheckBox();
            this.label5 = new System.Windows.Forms.Label();
            this.txtReportStart = new System.Windows.Forms.TextBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.rdAutomaticStart = new System.Windows.Forms.RadioButton();
            this.rdManualStart = new System.Windows.Forms.RadioButton();
            this.tabExecution = new System.Windows.Forms.TabPage();
            this.btnGrants = new System.Windows.Forms.Button();
            this.btnAttributes = new System.Windows.Forms.Button();
            this.label11 = new System.Windows.Forms.Label();
            this.txtReportExecution = new System.Windows.Forms.TextBox();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.rdAutomaticExecution = new System.Windows.Forms.RadioButton();
            this.rdManualExecution = new System.Windows.Forms.RadioButton();
            this.groupBox4 = new System.Windows.Forms.GroupBox();
            this.btnAction = new System.Windows.Forms.Button();
            this.cmbDataTypes = new System.Windows.Forms.ComboBox();
            this.label7 = new System.Windows.Forms.Label();
            this.cmbScriptType = new System.Windows.Forms.ComboBox();
            this.label8 = new System.Windows.Forms.Label();
            this.label9 = new System.Windows.Forms.Label();
            this.cmbExecutionType = new System.Windows.Forms.ComboBox();
            this.tabFinish = new System.Windows.Forms.TabPage();
            this.label10 = new System.Windows.Forms.Label();
            this.txtReportFinish = new System.Windows.Forms.TextBox();
            this.groupBox5 = new System.Windows.Forms.GroupBox();
            this.rdAutomaticFinish = new System.Windows.Forms.RadioButton();
            this.rdManualFinish = new System.Windows.Forms.RadioButton();
            this.label4 = new System.Windows.Forms.Label();
            this.cmbCatchType = new System.Windows.Forms.ComboBox();
            this.label3 = new System.Windows.Forms.Label();
            this.cmbType = new System.Windows.Forms.ComboBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtDescription = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.txtName = new System.Windows.Forms.TextBox();
            this.chkViewName = new System.Windows.Forms.CheckBox();
            this.panel2.SuspendLayout();
            this.tabBehaviour.SuspendLayout();
            this.tabStart.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.tabExecution.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.groupBox4.SuspendLayout();
            this.tabFinish.SuspendLayout();
            this.groupBox5.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel2
            // 
            this.panel2.Controls.Add(this.btnName);
            this.panel2.Controls.Add(this.btnCancel);
            this.panel2.Controls.Add(this.btnSave);
            this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panel2.Location = new System.Drawing.Point(0, 481);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(702, 49);
            this.panel2.TabIndex = 14;
            // 
            // btnName
            // 
            this.btnName.Dock = System.Windows.Forms.DockStyle.Right;
            this.btnName.Location = new System.Drawing.Point(536, 0);
            this.btnName.Name = "btnName";
            this.btnName.Size = new System.Drawing.Size(100, 49);
            this.btnName.TabIndex = 11;
            this.btnName.Text = "XML";
            this.btnName.Click += new System.EventHandler(this.btnName_Click);
            // 
            // btnCancel
            // 
            this.btnCancel.Dock = System.Windows.Forms.DockStyle.Left;
            this.btnCancel.Location = new System.Drawing.Point(0, 0);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(60, 49);
            this.btnCancel.TabIndex = 10;
            this.btnCancel.Text = "Cancel";
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // btnSave
            // 
            this.btnSave.Dock = System.Windows.Forms.DockStyle.Right;
            this.btnSave.Location = new System.Drawing.Point(636, 0);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(66, 49);
            this.btnSave.TabIndex = 9;
            this.btnSave.Text = "Save";
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // tabBehaviour
            // 
            this.tabBehaviour.Controls.Add(this.tabStart);
            this.tabBehaviour.Controls.Add(this.tabExecution);
            this.tabBehaviour.Controls.Add(this.tabFinish);
            this.tabBehaviour.Location = new System.Drawing.Point(0, 149);
            this.tabBehaviour.Name = "tabBehaviour";
            this.tabBehaviour.SelectedIndex = 0;
            this.tabBehaviour.Size = new System.Drawing.Size(687, 324);
            this.tabBehaviour.TabIndex = 15;
            // 
            // tabStart
            // 
            this.tabStart.Controls.Add(this.chkOnlyOne);
            this.tabStart.Controls.Add(this.label5);
            this.tabStart.Controls.Add(this.txtReportStart);
            this.tabStart.Controls.Add(this.groupBox1);
            this.tabStart.Location = new System.Drawing.Point(4, 22);
            this.tabStart.Name = "tabStart";
            this.tabStart.Size = new System.Drawing.Size(679, 298);
            this.tabStart.TabIndex = 0;
            this.tabStart.Text = "Start";
            // 
            // chkOnlyOne
            // 
            this.chkOnlyOne.Location = new System.Drawing.Point(187, 28);
            this.chkOnlyOne.Name = "chkOnlyOne";
            this.chkOnlyOne.Size = new System.Drawing.Size(206, 27);
            this.chkOnlyOne.TabIndex = 10;
            this.chkOnlyOne.Text = "Only One";
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(7, 69);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(73, 14);
            this.label5.TabIndex = 9;
            this.label5.Text = "Report";
            // 
            // txtReportStart
            // 
            this.txtReportStart.Location = new System.Drawing.Point(7, 83);
            this.txtReportStart.Multiline = true;
            this.txtReportStart.Name = "txtReportStart";
            this.txtReportStart.Size = new System.Drawing.Size(669, 125);
            this.txtReportStart.TabIndex = 8;
            this.txtReportStart.Text = "textBox1";
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.rdAutomaticStart);
            this.groupBox1.Controls.Add(this.rdManualStart);
            this.groupBox1.Location = new System.Drawing.Point(7, 14);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(166, 48);
            this.groupBox1.TabIndex = 5;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Mode";
            // 
            // rdAutomaticStart
            // 
            this.rdAutomaticStart.Checked = true;
            this.rdAutomaticStart.Location = new System.Drawing.Point(87, 21);
            this.rdAutomaticStart.Name = "rdAutomaticStart";
            this.rdAutomaticStart.Size = new System.Drawing.Size(73, 20);
            this.rdAutomaticStart.TabIndex = 1;
            this.rdAutomaticStart.TabStop = true;
            this.rdAutomaticStart.Text = "Automatic";
            // 
            // rdManualStart
            // 
            this.rdManualStart.Location = new System.Drawing.Point(20, 21);
            this.rdManualStart.Name = "rdManualStart";
            this.rdManualStart.Size = new System.Drawing.Size(80, 21);
            this.rdManualStart.TabIndex = 0;
            this.rdManualStart.Text = "Manual";
            // 
            // tabExecution
            // 
            this.tabExecution.Controls.Add(this.btnGrants);
            this.tabExecution.Controls.Add(this.btnAttributes);
            this.tabExecution.Controls.Add(this.label11);
            this.tabExecution.Controls.Add(this.txtReportExecution);
            this.tabExecution.Controls.Add(this.groupBox3);
            this.tabExecution.Controls.Add(this.groupBox4);
            this.tabExecution.Controls.Add(this.label9);
            this.tabExecution.Controls.Add(this.cmbExecutionType);
            this.tabExecution.Location = new System.Drawing.Point(4, 22);
            this.tabExecution.Name = "tabExecution";
            this.tabExecution.Size = new System.Drawing.Size(679, 298);
            this.tabExecution.TabIndex = 1;
            this.tabExecution.Text = "Execution";
            this.tabExecution.Visible = false;
            // 
            // btnGrants
            // 
            this.btnGrants.Location = new System.Drawing.Point(473, 69);
            this.btnGrants.Name = "btnGrants";
            this.btnGrants.Size = new System.Drawing.Size(134, 21);
            this.btnGrants.TabIndex = 17;
            this.btnGrants.Text = "Grants";
            this.btnGrants.Click += new System.EventHandler(this.btnGrants_Click);
            // 
            // btnAttributes
            // 
            this.btnAttributes.Location = new System.Drawing.Point(473, 35);
            this.btnAttributes.Name = "btnAttributes";
            this.btnAttributes.Size = new System.Drawing.Size(134, 20);
            this.btnAttributes.TabIndex = 16;
            this.btnAttributes.Text = "Attributes";
            this.btnAttributes.Click += new System.EventHandler(this.btnAttributes_Click);
            // 
            // label11
            // 
            this.label11.Location = new System.Drawing.Point(13, 153);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(74, 13);
            this.label11.TabIndex = 14;
            this.label11.Text = "Report";
            // 
            // txtReportExecution
            // 
            this.txtReportExecution.Location = new System.Drawing.Point(13, 166);
            this.txtReportExecution.Multiline = true;
            this.txtReportExecution.Name = "txtReportExecution";
            this.txtReportExecution.Size = new System.Drawing.Size(654, 125);
            this.txtReportExecution.TabIndex = 13;
            this.txtReportExecution.Text = "textBox1";
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.rdAutomaticExecution);
            this.groupBox3.Controls.Add(this.rdManualExecution);
            this.groupBox3.Location = new System.Drawing.Point(7, 14);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(166, 48);
            this.groupBox3.TabIndex = 12;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Mode";
            // 
            // rdAutomaticExecution
            // 
            this.rdAutomaticExecution.Checked = true;
            this.rdAutomaticExecution.Location = new System.Drawing.Point(87, 21);
            this.rdAutomaticExecution.Name = "rdAutomaticExecution";
            this.rdAutomaticExecution.Size = new System.Drawing.Size(73, 21);
            this.rdAutomaticExecution.TabIndex = 1;
            this.rdAutomaticExecution.TabStop = true;
            this.rdAutomaticExecution.Text = "Automatic";
            // 
            // rdManualExecution
            // 
            this.rdManualExecution.Location = new System.Drawing.Point(20, 21);
            this.rdManualExecution.Name = "rdManualExecution";
            this.rdManualExecution.Size = new System.Drawing.Size(80, 21);
            this.rdManualExecution.TabIndex = 0;
            this.rdManualExecution.Text = "Manual";
            // 
            // groupBox4
            // 
            this.groupBox4.Controls.Add(this.btnAction);
            this.groupBox4.Controls.Add(this.cmbDataTypes);
            this.groupBox4.Controls.Add(this.label7);
            this.groupBox4.Controls.Add(this.cmbScriptType);
            this.groupBox4.Controls.Add(this.label8);
            this.groupBox4.Location = new System.Drawing.Point(7, 69);
            this.groupBox4.Name = "groupBox4";
            this.groupBox4.Size = new System.Drawing.Size(406, 70);
            this.groupBox4.TabIndex = 6;
            this.groupBox4.TabStop = false;
            this.groupBox4.Text = "Script";
            // 
            // btnAction
            // 
            this.btnAction.Location = new System.Drawing.Point(367, 35);
            this.btnAction.Name = "btnAction";
            this.btnAction.Size = new System.Drawing.Size(33, 20);
            this.btnAction.TabIndex = 12;
            this.btnAction.Text = "...";
            this.btnAction.Click += new System.EventHandler(this.btnAction_Click);
            // 
            // cmbDataTypes
            // 
            this.cmbDataTypes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbDataTypes.Location = new System.Drawing.Point(160, 35);
            this.cmbDataTypes.Name = "cmbDataTypes";
            this.cmbDataTypes.Size = new System.Drawing.Size(193, 21);
            this.cmbDataTypes.Sorted = true;
            this.cmbDataTypes.TabIndex = 11;
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(13, 21);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(67, 14);
            this.label7.TabIndex = 10;
            this.label7.Text = "Script Type";
            // 
            // cmbScriptType
            // 
            this.cmbScriptType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbScriptType.Location = new System.Drawing.Point(13, 35);
            this.cmbScriptType.Name = "cmbScriptType";
            this.cmbScriptType.Size = new System.Drawing.Size(134, 21);
            this.cmbScriptType.TabIndex = 9;
            // 
            // label8
            // 
            this.label8.Location = new System.Drawing.Point(160, 21);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(87, 14);
            this.label8.TabIndex = 7;
            this.label8.Text = "Name DataType";
            // 
            // label9
            // 
            this.label9.Location = new System.Drawing.Point(193, 14);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(34, 14);
            this.label9.TabIndex = 4;
            this.label9.Text = "Type";
            // 
            // cmbExecutionType
            // 
            this.cmbExecutionType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbExecutionType.Location = new System.Drawing.Point(193, 35);
            this.cmbExecutionType.Name = "cmbExecutionType";
            this.cmbExecutionType.Size = new System.Drawing.Size(200, 21);
            this.cmbExecutionType.TabIndex = 1;
            // 
            // tabFinish
            // 
            this.tabFinish.Controls.Add(this.label10);
            this.tabFinish.Controls.Add(this.txtReportFinish);
            this.tabFinish.Controls.Add(this.groupBox5);
            this.tabFinish.Location = new System.Drawing.Point(4, 22);
            this.tabFinish.Name = "tabFinish";
            this.tabFinish.Size = new System.Drawing.Size(679, 298);
            this.tabFinish.TabIndex = 2;
            this.tabFinish.Text = "Finish";
            this.tabFinish.Visible = false;
            // 
            // label10
            // 
            this.label10.Location = new System.Drawing.Point(7, 69);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(73, 14);
            this.label10.TabIndex = 14;
            this.label10.Text = "Report";
            // 
            // txtReportFinish
            // 
            this.txtReportFinish.Location = new System.Drawing.Point(7, 83);
            this.txtReportFinish.Multiline = true;
            this.txtReportFinish.Name = "txtReportFinish";
            this.txtReportFinish.Size = new System.Drawing.Size(686, 125);
            this.txtReportFinish.TabIndex = 13;
            this.txtReportFinish.Text = "textBox1";
            // 
            // groupBox5
            // 
            this.groupBox5.Controls.Add(this.rdAutomaticFinish);
            this.groupBox5.Controls.Add(this.rdManualFinish);
            this.groupBox5.Location = new System.Drawing.Point(7, 14);
            this.groupBox5.Name = "groupBox5";
            this.groupBox5.Size = new System.Drawing.Size(166, 48);
            this.groupBox5.TabIndex = 12;
            this.groupBox5.TabStop = false;
            this.groupBox5.Text = "Mode";
            // 
            // rdAutomaticFinish
            // 
            this.rdAutomaticFinish.Checked = true;
            this.rdAutomaticFinish.Location = new System.Drawing.Point(87, 21);
            this.rdAutomaticFinish.Name = "rdAutomaticFinish";
            this.rdAutomaticFinish.Size = new System.Drawing.Size(73, 21);
            this.rdAutomaticFinish.TabIndex = 1;
            this.rdAutomaticFinish.TabStop = true;
            this.rdAutomaticFinish.Text = "Automatic";
            // 
            // rdManualFinish
            // 
            this.rdManualFinish.Location = new System.Drawing.Point(20, 21);
            this.rdManualFinish.Name = "rdManualFinish";
            this.rdManualFinish.Size = new System.Drawing.Size(80, 21);
            this.rdManualFinish.TabIndex = 0;
            this.rdManualFinish.Text = "Manual";
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(533, 14);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(80, 14);
            this.label4.TabIndex = 23;
            this.label4.Text = "Catch";
            // 
            // cmbCatchType
            // 
            this.cmbCatchType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbCatchType.Enabled = false;
            this.cmbCatchType.ItemHeight = 13;
            this.cmbCatchType.Location = new System.Drawing.Point(533, 28);
            this.cmbCatchType.Name = "cmbCatchType";
            this.cmbCatchType.Size = new System.Drawing.Size(167, 21);
            this.cmbCatchType.TabIndex = 22;
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(360, 14);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(80, 14);
            this.label3.TabIndex = 21;
            this.label3.Text = "Type";
            // 
            // cmbType
            // 
            this.cmbType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbType.ItemHeight = 13;
            this.cmbType.Location = new System.Drawing.Point(360, 28);
            this.cmbType.Name = "cmbType";
            this.cmbType.Size = new System.Drawing.Size(167, 21);
            this.cmbType.TabIndex = 20;
            this.cmbType.SelectedIndexChanged += new System.EventHandler(this.cmbType_SelectedIndexChanged);
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(7, 64);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(120, 14);
            this.label2.TabIndex = 19;
            this.label2.Text = "Description";
            // 
            // txtDescription
            // 
            this.txtDescription.Location = new System.Drawing.Point(7, 81);
            this.txtDescription.Multiline = true;
            this.txtDescription.Name = "txtDescription";
            this.txtDescription.Size = new System.Drawing.Size(686, 62);
            this.txtDescription.TabIndex = 18;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(7, 7);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(86, 14);
            this.label1.TabIndex = 17;
            this.label1.Text = "Name";
            // 
            // txtName
            // 
            this.txtName.Location = new System.Drawing.Point(7, 28);
            this.txtName.Name = "txtName";
            this.txtName.Size = new System.Drawing.Size(333, 20);
            this.txtName.TabIndex = 16;
            // 
            // chkViewName
            // 
            this.chkViewName.Checked = true;
            this.chkViewName.CheckState = System.Windows.Forms.CheckState.Checked;
            this.chkViewName.Location = new System.Drawing.Point(183, 7);
            this.chkViewName.Name = "chkViewName";
            this.chkViewName.Size = new System.Drawing.Size(157, 21);
            this.chkViewName.TabIndex = 24;
            this.chkViewName.Text = "View in Canvas";
            this.chkViewName.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // FormActivity
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(702, 530);
            this.ControlBox = false;
            this.Controls.Add(this.chkViewName);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.cmbCatchType);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.cmbType);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtDescription);
            this.Controls.Add(this.txtName);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.tabBehaviour);
            this.Controls.Add(this.panel2);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "FormActivity";
            this.Text = "Activity";
            this.panel2.ResumeLayout(false);
            this.tabBehaviour.ResumeLayout(false);
            this.tabStart.ResumeLayout(false);
            this.tabStart.PerformLayout();
            this.groupBox1.ResumeLayout(false);
            this.tabExecution.ResumeLayout(false);
            this.tabExecution.PerformLayout();
            this.groupBox3.ResumeLayout(false);
            this.groupBox4.ResumeLayout(false);
            this.tabFinish.ResumeLayout(false);
            this.tabFinish.PerformLayout();
            this.groupBox5.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		public void BindObject(/*Visio.Shape oShape*/)
		{
			bool bTypeSelectionable = true;
			

			if (true/*oShape.Data1!=""*/)
			{
				//xmlActivity.Parse(oShape.Data1);

                String sShapeId = "";//Utility.GetMasterNameU(oShape);
				if ( sShapeId == COLLAPSED_SUBPROCESS_MASTER) 
				{
					xmlActivity.Type = XMLActivity.SUBFLOW_TYPE;
					bTypeSelectionable = false;
				}
			}
				
			//add by mfarina on 01/10/2005
			else
			{
                String sShapeId = "";// Utility.GetMasterNameU(oShape);
				if ( sShapeId == COLLAPSED_SUBPROCESS_MASTER) 
				{
					xmlActivity.Type = XMLActivity.SUBFLOW_TYPE;
					bTypeSelectionable = false;
				}
			}

			this.FillForm ();

			this.cmbType.Enabled  = bTypeSelectionable;
		}

		private void FillForm()
		{
			// fills all filds with the activity value
			this.txtName.Text=xmlActivity.Name;
			this.txtDescription.Text=xmlActivity.Description;
			this.cmbType.Text=xmlActivity.Type;
			this.cmbCatchType.Text=xmlActivity.CatchType;

			#region Behaviour

			XMLBehaviour m_Behaviour = xmlActivity.XMLBehaviour;
			this.txtReportStart.Text=m_Behaviour.XMLBehaviourStart.Report;
			
			switch(m_Behaviour.XMLBehaviourStart.Mode)       
			{         
				
				case XMLBehaviourStart.AUTOMATIC_MODE:   
					this.rdAutomaticStart.Checked=true;
					break;                  
				case XMLBehaviourStart.MANUAL_MODE:            
					this.rdManualStart.Checked=true;
					break;
				default:
					this.rdAutomaticStart.Checked=true;
					break;
			}

			switch(m_Behaviour.XMLBehaviourStart.OnlyOne)       
			{         
				
				case XMLBehaviourStart.NO_ONLYONE:   
					this.chkOnlyOne.Checked=false;
					break;                  
				case XMLBehaviourStart.YES_ONLYONE:            
					this.chkOnlyOne.Checked=true;
					break;
				default:
					this.chkOnlyOne.Checked=true;
					break;
			}



			//Execution setup
			this.txtReportExecution.Text=m_Behaviour.XMLBehaviourExecution.Report;
			//this.txtScript.Text=m_Behaviour.XMLBehaviourExecution.XMLScript.Value;
			this.cmbDataTypes.Text=m_Behaviour.XMLBehaviourExecution.XMLScript.DataType;
			this.cmbScriptType.Text=m_Behaviour.XMLBehaviourExecution.XMLScript.Type;
			this.cmbType.Text=m_Behaviour.XMLBehaviourExecution.Type;
			
			switch(m_Behaviour.XMLBehaviourExecution.Mode)       
			{         
				
				case XMLBehaviourExecution.AUTOMATIC_MODE:   
					this.rdAutomaticExecution.Checked=true;
					break;                  
				case XMLBehaviourExecution.MANUAL_MODE:            
					this.rdManualExecution.Checked=true;
					break;
				default:
					this.rdAutomaticExecution.Checked=true;
					break;
			}

			

			//Finish setup
			this.txtReportFinish.Text=m_Behaviour.XMLBehaviourFinish.Report;


			// to be continue..

			switch(m_Behaviour.XMLBehaviourFinish.Mode)       
			{         
				
				case XMLBehaviourFinish.AUTOMATIC_MODE:   
					this.rdAutomaticFinish.Checked=true;
					break;                  
				case XMLBehaviourFinish.MANUAL_MODE:            
					this.rdManualFinish.Checked=true;
					break;
				default:
					this.rdAutomaticFinish.Checked=true;
					break;
			}
			#endregion

		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			xmlActivity.Name=this.txtName.Text;
			xmlActivity.Description=this.txtDescription.Text;
			xmlActivity.Type=this.cmbType.Text;
			xmlActivity.CatchType=this.cmbCatchType.Text;

			if ( xmlActivity.Type == XMLActivity.THROWER_TYPE) 
			{
				xmlActivity.ReferenceActivity = "Catcher_" + xmlActivity.Name;
			}


			XMLBehaviour m_Behaviour = xmlActivity.XMLBehaviour;

			m_Behaviour.XMLBehaviourStart.Report=this.txtReportStart.Text;
			if (this.rdManualStart.Checked==true) m_Behaviour.XMLBehaviourStart.Mode=XMLBehaviourStart.MANUAL_MODE;
			if (this.rdAutomaticStart.Checked==true) m_Behaviour.XMLBehaviourStart.Mode=XMLBehaviourStart.AUTOMATIC_MODE;

			if (this.chkOnlyOne.Checked==true) 
				m_Behaviour.XMLBehaviourStart.OnlyOne=XMLBehaviourStart.YES_ONLYONE;
			else
				m_Behaviour.XMLBehaviourStart.OnlyOne=XMLBehaviourStart.NO_ONLYONE;


			//Execution behaviour
			m_Behaviour.XMLBehaviourExecution.Type=this.cmbType.Text;
			m_Behaviour.XMLBehaviourExecution.Report=this.txtReportExecution.Text;		
			//m_Behaviour.XMLBehaviourExecution.XMLScript.Value=this.txtScript.Text;
			m_Behaviour.XMLBehaviourExecution.XMLScript.DataType=this.cmbDataTypes.Text;
			m_Behaviour.XMLBehaviourExecution.XMLScript.Type=this.cmbScriptType.Text;
			if (this.rdManualExecution.Checked==true) m_Behaviour.XMLBehaviourExecution.Mode=XMLBehaviourExecution.MANUAL_MODE;
			if (this.rdAutomaticExecution.Checked==true) m_Behaviour.XMLBehaviourExecution.Mode=XMLBehaviourExecution.AUTOMATIC_MODE;

				

			//finish behaviour
			m_Behaviour.XMLBehaviourFinish.Report=this.txtReportFinish.Text;
			if (this.rdManualFinish.Checked==true) m_Behaviour.XMLBehaviourFinish.Mode=XMLBehaviourFinish.MANUAL_MODE;
			if (this.rdAutomaticFinish.Checked==true) m_Behaviour.XMLBehaviourFinish.Mode=XMLBehaviourFinish.AUTOMATIC_MODE;

            /*
			if ( m_Shape != null )
			{	
				m_Shape.Data1=xmlActivity.GetXML();

				if ( this.chkViewName.Checked )
				{
					m_Shape.Text=this.txtName.Text;
				}
				else
				{
					m_Shape.Text=string.Empty;
				}
			}
            */
			this.Close();

		}

		private void LoadControl(string sActivity)
		{
			try 
			{
				#region Type e CatcherType

				if ( sActivity.IndexOf ("Gateway") >=0 )
				{
					cmbType.Items.Add (XMLActivity.CONDITION_TYPE);
					cmbType.Items.Add (XMLActivity.CATCHER_TYPE);
					cmbType.Items.Add (XMLActivity.THROWER_TYPE);

					cmbCatchType.Items.Add(XMLActivity.EVER_CATCH_TYPE);
					cmbCatchType.Items.Add(XMLActivity.NEVER_CATCH_TYPE);
					cmbCatchType.Items.Add(XMLActivity.ONLY_ONE_CATCH_TYPE);
				}
				else
				{
					cmbType.Items.Add (XMLActivity.API_TYPE);
					cmbType.Items.Add (XMLActivity.SUBFLOW_TYPE);
					cmbType.Items.Add (XMLActivity.APPLICATION_TYPE);
					cmbType.Items.Add (XMLActivity.EMAIL_TYPE);
					cmbType.Items.Add (XMLActivity.XML_TYPE);
					cmbType.Items.Add (XMLActivity.EVENT_TYPE);
					cmbType.Items.Add (XMLActivity.END_TYPE);
					cmbType.Items.Add (XMLActivity.EXIT_TYPE);
					cmbType.Items.Add (XMLActivity.CONDITION_TYPE);
				}
				
				#endregion

				#region ExecutionType
				//cmbExecutionType.Items.Add (XMLBehaviourExecution.BLOCKACTIVITY_TYPE);
				cmbExecutionType.Items.Add (XMLBehaviourExecution.IMPLEMENTATION_TYPE);
				cmbExecutionType.SelectedIndex = 0;
				//cmbExecutionType.Items.Add (XMLBehaviourExecution.ROUTE_TYPE);
				#endregion

				#region DataTypes
                m_DataTypes = Engine.DataTypesHelper.GetDataTypes();
				foreach (WorkflowDataTypes.XMLDataType o_DataType in m_DataTypes)
				{		
					cmbDataTypes.Items.Add(o_DataType.Key);
				}
				#endregion

			}
			catch (Exception err) 
			{
				// Let the user know what went wrong.
				Console.WriteLine("The file could not be read:");
				Console.WriteLine(err.Message);
			}
		}


		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void cmbType_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.cmbCatchType.Enabled  = false;
			cmbScriptType.Items.Clear();

			switch ( this.cmbType.Text ) 
			{
				case (XMLActivity.API_TYPE):
					cmbScriptType.Items.Add(XMLScript.API_ASYNC_TYPE);
					cmbScriptType.Items.Add(XMLScript.API_SYNCH_TYPE);
					break;

				case (XMLActivity.SUBFLOW_TYPE):
					cmbScriptType.Items.Add(XMLScript.SUBFLOW_ASYNC_TYPE);
					cmbScriptType.Items.Add(XMLScript.SUBFLOW_SYNCH_TYPE);
					cmbScriptType.Items.Add(XMLScript.SUBFLOW_SPECIAL_TYPE);
					break;

				case (XMLActivity.CONDITION_TYPE):
					cmbScriptType.Items.Add(XMLScript.EVAL_EXPRESSION_TYPE);
					cmbScriptType.Items.Add(XMLScript.LOOP_COUNTER_TYPE);
					cmbScriptType.Items.Add(XMLScript.LOOP_EXPRESSION_TYPE);
					break;

				case (XMLActivity.EVENT_TYPE):
					cmbScriptType.Items.Add(XMLScript.EVENT_CONSUMER_TYPE);
					cmbScriptType.Items.Add(XMLScript.EVENT_MAKER_TYPE);
					break;

				case (XMLActivity.END_TYPE):
				case (XMLActivity.EXIT_TYPE):
					cmbScriptType.Items.Add(XMLScript.NONE_TYPE);
					break;

				case (XMLActivity.THROWER_TYPE):
					cmbScriptType.Items.Add(XMLScript.EVAL_EXPRESSION_TYPE);
					break;

				case (XMLActivity.CATCHER_TYPE):
					this.cmbCatchType.Enabled = true;
					break;

				case (XMLActivity.APPLICATION_TYPE):
					cmbScriptType.Items.Add(XMLScript.APPLICATION_API_TYPE);
					break;

				case (XMLActivity.EMAIL_TYPE):
					cmbScriptType.Items.Add(XMLScript.EMAIL_SMTP_TYPE);
					break;

				case (XMLActivity.XML_TYPE):
					cmbScriptType.Items.Add(XMLScript.XML_XSLT_TYPE);
					break;
			}

			//Adding Embedded Attributes if not present in Activity
			WorkflowRelevantData.XMLAttributes vEmbedded = WorkflowProcesses.XMLActivity.GetEmbeddedAttributes ( this.cmbType.Text);
			WorkflowRelevantData.XMLAttribute attribute = null;
			for ( int i=0; i<vEmbedded.Count; i++)
			{
				try
				{
					attribute = xmlActivity.XMLAttributes.Get ( ((WorkflowRelevantData.XMLAttribute)vEmbedded[i]).Name);
				}
				catch ( Scenario.WorkflowEngine.DataModel.Exception.AttributeNotFound )
				{
					xmlActivity.XMLAttributes.Add ( ((WorkflowRelevantData.XMLAttribute)vEmbedded[i]) );
				}
			}
		}

		private void btnAction_Click(object sender, System.EventArgs e)
		{
			string sScript = xmlActivity.XMLBehaviour.XMLBehaviourExecution.XMLScript.Value;

			switch ( this.cmbScriptType.Text ) 
			{
				case XMLScript.APPLICATION_API_TYPE:
					

					FormApplications frmApplications = null;
					if ( sScript.Length > 0 )
					{
						WorkflowApplicationsData.XMLApplicationFunction function = new WorkflowApplicationsData.XMLApplicationFunction();

						try
						{
							function.Parse(sScript);
						}
						catch //useful. sScript could be not a function.
						{
						}

						frmApplications = new FormApplications(function);
					}
					else
					{
						frmApplications = new FormApplications();
					}
					frmApplications.XMLAttributes = this.vAttributes;

					frmApplications.ShowDialog (this);

					if ( frmApplications.xmlApplicationFunction != null )
					{
						xmlActivity.XMLBehaviour.XMLBehaviourExecution.XMLScript.Value = frmApplications.xmlApplicationFunction.GetXML();
					}

					break;

				default:
					
					FormScriptAction frmScript = new FormScriptAction(sScript);
					frmScript.ShowDialog (this);

					if ( frmScript.xmlScript != null )
					{
						xmlActivity.XMLBehaviour.XMLBehaviourExecution.XMLScript.Value = frmScript.xmlScript.Value;
					}
					break;
			}
		}

		private void btnAttributes_Click(object sender, System.EventArgs e)
		{
			WorkflowRelevantData.XMLAttributes vAttributes = xmlActivity.XMLAttributes;
			FormAttributes frmAttributes =new FormAttributes ( ref vAttributes, WorkflowProcesses.XMLActivity.GetEmbeddedAttributes (this.cmbType.Text ) );
			frmAttributes.ShowDialog (this);

			xmlActivity.XMLAttributes = vAttributes;
		}

		private void btnGrants_Click(object sender, System.EventArgs e)
		{
			FormGrants frmGrants = new FormGrants (xmlActivity.XMLGrants, ref xmlRoles);
			frmGrants.ShowDialog (this);

			if ( frmGrants.XMLGrants != null )
			{
				xmlActivity.XMLGrants = frmGrants.XMLGrants;
			}
		}

		private void btnName_Click(object sender, System.EventArgs e)
		{
			FormXML frmXML = new FormXML();
			if ( xmlActivity != null )
			{
				frmXML.XML = xmlActivity.GetXML(true, 0);
			}
			frmXML.ShowDialog(this);

			if ( frmXML.OK )
			{
				xmlActivity.Parse ( frmXML.XML);
                /*
				if ( m_Shape != null )
				{	
					m_Shape.Data1=frmXML.XML;
					m_Shape.Text=xmlActivity.Name;
				}
                */
			}
			this.Close();
		}
	}
}
